<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单击双击事件</title>
</head>
<body>
    <button>点击</button>
    
    <script>   
    let timeId = null
        window.onclick = () => { //单击click
            clearTimeout(timeId);
            timeId = setTimeout(() => {
                alert('吃冰激凌');
            },300)
  
        }
        window.ondblclick = () => { //双击dblclick
            clearTimeout(timeId);
            alert('吃蛋糕');

        }
        
// 练习:单击时触发单击事件， 双击时只触发双击事件
// BOM:setTimeOut()
//  btn.addEventListener('click',fn);
//     btn.addEventListener('dblclick',fn1);
//     function fn() {
//         alert('2班');
//         btn.removeEventListener('click',fn);
//     }
//     function fn1() {
//         alert('4班');
//     }
    </script>
</body>
</html>